﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class HealthPickup : MonoBehaviour
{
    public float recover = 20f;
    public float dropTime;
    Animator animator; 
    // Start is called before the first frame update
    void Start()
    {
        animator = transform.root.GetComponent<Animator>();
        Invoke("Drop", dropTime);
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    void OnCollisionEnter2D(Collision2D col)
    {
        if (col.gameObject.tag == "Ground") animator.SetTrigger("land");
        else if(col.gameObject.tag== "Player")
        {
            GameObject.Find("HealthBar").GetComponent<HealthBar>().takeDamage(-recover);
            col.gameObject.GetComponent<Items>().getHeal();
            Destroy(transform.root.gameObject);
        }
    }

    public void Drop()
    {
        Debug.Log("dd");
        GetComponent<BoxCollider2D>().isTrigger = true;
        transform.root.GetComponent<Rigidbody2D>().AddForce(Vector2.down * 100);
    }
}
